package com.youlu.campus.web.order.controller;

import com.youlu.campus.entity.VO.req.QQMiniPlaceOrderReq;
import com.youlu.campus.web.order.service.QQMiniOrderService;
import com.youlu.campus.web.common.base.RequestContext;
import com.youlu.campus.web.common.utils.CommonUtils;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
public class QQMiniOrderController {

    @Autowired
    private QQMiniOrderService qqMiniOrderService;

    /**
     * QQ 小程序下单接口
     *
     * @param placeOrderReq
     * @return
     */
    @PostMapping("/mini-app/qq/place-order")
    public QResult placeOrder(@RequestBody @Validated QQMiniPlaceOrderReq placeOrderReq, HttpServletRequest request) {
        placeOrderReq.setCurrentUser(RequestContext.getCurUser());
        placeOrderReq.setPlatform(RequestContext.getCurPlatform());
        placeOrderReq.setAppId(RequestContext.getAppId());
        placeOrderReq.setClientIp(CommonUtils.getRemoteIp(request));
        placeOrderReq.setOpenId(RequestContext.getCurUser().getOpenId());
        return QResult.success(qqMiniOrderService.placeOrder(placeOrderReq));
    }
    @GetMapping("/mini-app/qq/order-detail")
    public QResult getOrder(@RequestParam("orderNo") String orderNo) {
        return QResult.success(qqMiniOrderService.getOrderInfo(orderNo));
    }
}
